<template>
<div id="background">
  <el-container>
    <el-header style="height:280px">
        <div style="height:200px">
          <van-swipe style="height:200px"  :autoplay="3000">
            <van-swipe-item v-for="news  in newsPics" :key="news.newsId">
              <img v-bind:src="news.newsPicture" style="width:100%"  />
            </van-swipe-item>
          </van-swipe>
        </div>
        <div>
          <el-row type="flex" style="backgroundColor:#ffffff;height:80px" justify="space-around" class="imgCol">
                    <el-col :xs="4" :sm="4" :md="4"  >
                        <div class="imgCol" >
                            <img v-bind:src="shiPinIcon"  class="mainIconSize"/>
                        </div>
                        <div class="imgCol">
                            <span class="words littleWords"  style="color:#53cdf5">视频课程</span>
                        </div>
                    </el-col>
                     <el-col :xs="4" :sm="4" :md="4" >
                        <div class="imgCol" >
                            <img v-bind:src="tiKuIcon"  class="mainIconSize"   @click="goToTiKu"/>
                        </div>
                        <div class="imgCol"  @click="goToTiKu">
                            <span class="words littleWords"   >题库训练</span>
                        </div>
                    </el-col>
                     <el-col :xs="4" :sm="4" :md="4"  >
                        <div class="imgCol" >
                            <img v-bind:src="shiCaoIcon"  class="mainIconSize" @click="goToShiCao"/>
                        </div>
                        <div class="imgCol" @click="goToShiCao">
                            <span class="words littleWords"  >实操培训</span>
                        </div>
                    </el-col>
                     <el-col :xs="4" :sm="4" :md="4"  >
                        <div class="imgCol" >
                            <img v-bind:src="kaoZhengIcon"  class="mainIconSize"/>
                        </div>
                        <div class="imgCol" @click="goToKaoZheng">
                            <span class="words littleWords" >考证报名</span>
                        </div>
                    </el-col>
                     <el-col :xs="4" :sm="4" :md="4"  >
                        <div class="imgCol" >
                            <img v-bind:src="weiPeiIcon"  class="mainIconSize"/>
                        </div>
                        <div class="imgCol" @click="goToDxwp">
                            <span class="words littleWords"  >定向委培</span>
                        </div>
                    </el-col>
          </el-row>
        </div>
    </el-header>
    <el-main id="mainPeiXun" style="backgroundColor:#ffffff">
      <sticky-slot>
       
          <van-tabs v-model="activeGongZhong" swipeable animated color="#53cdf5" @change="showGongZhong">
            <van-tab v-for="index in gongZhongs" v-bind:key="index.professionId" :title="index.professionName" :name="index.professionId">
            </van-tab>
          </van-tabs>

      </sticky-slot>
      <div>
        <div v-show="!courseInfo.total" style="margin-top:20px">
          <span class="words imgCol" >此工种暂无课程</span>
        </div>
        <div v-show="courseInfo.total">
               
                  <div  v-infinite-scroll="load" infinite-scroll-disabled="disabled" v-for="shiPin in shiPins" v-bind:key="shiPin.id" style="margin-top:10px" @click="goToShiPin(shiPin.courseId)">
                    <el-col  :xs="12" :sm="12" :md="12">
                      <el-card style="margin-left: 10px; margin-right: 10px;margin-top:10px;height:130px" :body-style="{ padding: '0px'}" >
                        <div  style="position:relative;text-align:center;">
                          
                          <el-image
                              style="width: 100%; height: 85px;border-radius:5px"
                              :src="shiPin.picture"
                              fit="cover">
                          </el-image>
                          <div style="position:absolute;left:0;top:60px;right:0;bottom:0px">
                            <el-row type="flex" justify="end"> 
                              <el-col :xs="6" :sm="6" :md="6" >
                                <span class="reMenTag">热门</span>
                              </el-col>
                            </el-row>
                          </div>
                        </div>
                        <div>
                          <el-row type="flex" justify="center" >
                              <el-col  :xs="11" :sm="12" :md="12" :offset="1" class="noHuanHang">
                                <span class="words">{{shiPin.name}}</span>
                              </el-col>
                              <el-col  :xs="11" :sm="11" :md="11" :offset="1" class="noHuanHang">
                                <span class="words">{{shiPin.teacher}}</span>
                              </el-col>
                          </el-row>
                          <el-row type="flex">
                            <el-col :xs="15" :sm="15" :md="15" :offset="1">
                              <span  style="color:#f16161">¥{{shiPin.price}}</span>
                            </el-col>
                            <el-col  :xs="7" :sm="7" :md="7" :offset="1">
                              <i class="el-icon-user-solid" style="font-size:12px;color:#707070"></i>
                              <span style="font-size:12px" class="noHuanHang">{{shiPin.number}}</span>
                            </el-col>
                          </el-row>
                        </div>
                      </el-card>
                    </el-col>
                  </div>
                  <div style="height:5px"></div>
                
        </div>
        
      </div>
      
    </el-main>
    <div style="height:5px;backgroundColor:#fff"></div>
    <div v-if="loading" class="imgCol" style="backgroundColor:#ffffff">
      <span class="words" style="font-size:14px">加载中...</span>
    </div>
    <div v-if="noMore" class="imgCol" style="backgroundColor:#ffffff">
      <span class="words" style="font-size:14px">没有更多了...</span>
    </div>
    <div style="height:65px;backgroundColor:#ffffff"></div>
    <el-footer id="peiXunBottomPosition" class="foot" >
        <div>
          <el-row type="flex" justify="space-around" style="margin-top:10px">
            <el-col :xs="6" :sm="6" :md="6" >
              <div class="imgCol" >
                <img v-bind:src="peiXunIcon"  class="mainIconSize" />
              </div>
              <div class="imgCol">
                <span class="words littleWords"  style="color:#53cdf5">培训</span>
              </div>
            </el-col>
            <el-col :xs="6" :sm="6" :md="6">
              <div class="imgCol">
                <img v-bind:src="zhaoPinIcon"  class="mainIconSize" @click="goToZhaoPin"/>
              </div>
              <div class="imgCol" @click="goToZhaoPin">
                <span class="words littleWords">招聘</span>
              </div>
            </el-col>
            <el-col :xs="6" :sm="6" :md="6">
              <div class="imgCol">
                <img v-bind:src="xiaoXiIcon"  class="mainIconSize" @click="goToXiaoXi"/>
                <!--<i class="el-icon-chat-dot-square" style="font-size:24px;color:#707070" ></i>-->
              </div>
              <div class="imgCol" @click="goToXiaoXi">
                <span class="words littleWords">消息</span>
              </div>
            </el-col>
            <el-col :xs="6" :sm="6" :md="6">
              <div class="imgCol">
                <img v-bind:src="woDeIcon"  style="color:#53cdf5" class="mainIconSize" @click="goToMine()"/>
              </div>
              <div class="imgCol"  @click="goToMine()">
                <span class="words littleWords"  >我的</span>
              </div>
            </el-col>
          </el-row>
        </div>
    </el-footer>
  </el-container>
</div>
</template>
<script>
import peiXunIcon from '../../assets/img/peiXun/peiXunChoose.png'
import zhaoPinIcon from '../../assets/img/mine/zhaopin.png'
import xiaoXiIcon from '../../assets/img/mine/news.png'
import woDeIcon from '../../assets/img/mine/mine.png'
import shiPinIcon from '../../assets/img/peiXun/shiPin.png'
import tiKuIcon from '../../assets/img/peiXun/tiKu.png'
import shiCaoIcon from '../../assets/img/peiXun/shiCao.png'
import kaoZhengIcon from '../../assets/img/peiXun/kaoZheng.png'
import weiPeiIcon from '../../assets/img/peiXun/weiPei.png'
import { Swipe, SwipeItem ,Toast} from 'vant';
import stickySlot from '../common/stickySlot/stickySlot.vue'
export default {
  components:{ 
    stickySlot,
  },
  data(){
    return{
            //绑定加载状态是否显示
            loading: false,

            // finished:false,
            // loading:false,
            // isLoading: false,
      
            peiXunIcon:peiXunIcon,
            zhaoPinIcon:zhaoPinIcon,
            xiaoXiIcon:xiaoXiIcon,
            woDeIcon:woDeIcon,
            shiPinIcon:shiPinIcon,
            tiKuIcon:tiKuIcon,
            shiCaoIcon:shiCaoIcon,
            kaoZhengIcon:kaoZhengIcon,
            weiPeiIcon:weiPeiIcon,
            normalHeight:document.documentElement.clientHeight,
            height:window.screen.height,
            normalWidth:document.documentElement.clientWidth,
            newsPics:[],

            activeGongZhong:'',
            gongZhongs:[],
            count:20,
            /**
             * {
                "number": 2,
                "teacher": "M老师",
                "price": 99.0,
                "name": "电工课程",
                "courseId": 201,
                "picture": "http://47.101.180.43:8075/static/course/1/1.jpg"
            }
             */
            shiPins:[],
            courseInfo:{
              size:6,
              id:1,
              num:1,
              total:0,
            },

    }
  },
  computed: {
      noMore () {
        return this.shiPins.length>=this.courseInfo.total
      },
      disabled () {
        return this.loading || this.noMore
      }
    },
  mounted(){
        this.getNewsSwipe();
        this.getZhiYes();
        this.getCourseYuLan();

        var normalHeight=sessionStorage.getItem('normalHeight');

        var bg = document.getElementById("background");
       // normalHeight=document.documentElement.clientHeight;
        console.log("height:"+normalHeight);
        bg.style.height = normalHeight+"px";
        bg.style.backgroundColor = "#FFFFFF"
        bg.style.margin = "0px";
  },

  methods:{

      goToDxwp(){
        this.$router.push({
                path:'/weiPei/dingXiangWeiPei'
            })
      },
      goToShiPin(courseId){
        console.log('这里是Id'+courseId);
        this.$router.push({
                path:'/peiXun/shiPing',
                 query:{
                    courseId:courseId
                },
            })
            
      },
        goToKaoZheng(){
          this.$router.push({
                path:'/kaoZheng'
            })
        },
        
        goToPeiXun(){
            this.$router.push({
                path:'/peiXun'
            })
        },
        goToMine(){
            this.$router.push({
                path:'/mine'
            })
        },
        goToXiaoXi(){
          this.$router.push({
            path:'/xiaoXi'
          })
        },
        goToZhaoPin(){
          this.$router.push({
            path:'/zhaoPin'
          })
        },
        goToTiKu(){
          console.log("tiku");
            this.$router.push({
              path:'/tiKu'
            })
        },
        goToShiCao(){
          console.log("shiCao");
          this.$router.push({
            path:'/shiCao'
          })
        },
        load () {
            this.loading = true
            setTimeout(() => {
            this.courseInfo.num++;
            this.getCourseYuLan();
            this.loading = false;

            }, 2000)
        },
        //获取新闻轮播图
        getNewsSwipe(){
          var URL=this.IP.IP+'/visitor/getNewsOutline';
            console.log(URL);
            this.$ajax({
                method:'get',
                url:URL,
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                    this.newsPics=response.data.data.newsOutline;
                }else{
                    Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        },
        //获取工种种类
        getZhiYes(){
            var URL=this.IP.IP+'/visitor/getProfessionInformation';
            console.log(URL);
            this.$ajax({
                method:'get',
                url:URL,
            }).then(response=>{
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                    this.gongZhongs=response.data.data.professionInformation;
                    this.courseInfo.id=this.gongZhongs[0].professionId;
                }else{
                    Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        },
        //根据工种ID获取课程预览
        getCourseYuLan(){
            var URL=this.IP.IP+'/course/general';
            console.log(URL);
            console.log("课程预览")
            console.log(this.courseInfo);
            this.$ajax({
                method:'get',
                url:URL,
                params:{
                  id:this.courseInfo.id,
                  pageNo:this.courseInfo.num,
                  pageSize:this.courseInfo.size,
                }
            }).then(response=>{
         
                console.log(response.data);
                var code=response.data.code;
                if(code==0){
                   // this.shiPins=response.data.data.info;
                   var i=0;
                   for(i=0;i<response.data.data.info.length;i++){
                     this.shiPins.push(response.data.data.info[i]);
                   }
                   this.courseInfo.total=response.data.data.total;
                    // 数据全部加载完成
                    if (this.shiPins.length >= this.courseInfo.total) {
                        console.log("finish");
                        this.finished = true;
                        this.loading=false;
                    }
                  
                   console.log(this.courseInfo.total);
                }else{
                   this.finished=true;
                    this.loading=false;
                    // Toast(response.data.msg);
                }
            }).catch(error=>{
                console.log(error);
                //Toast(error);
            })
        },
        //选择工种不同时触发
        showGongZhong(id){
  
          console.log("工种：");
          this.courseInfo.id=id;
          // this.finished=false;
          console.log(this.courseInfo.id);
          this.shiPins=[];
          this.more=false;
          this.courseInfo.num=1;
          this.getCourseYuLan();
        },
 
    }
}
</script>
<style>
/**
.el-card__header {
    background-image: url('../../assets/img/peiXun/shiPinBackground.png');
}*/
.foot{
  position: fixed;
  bottom: 0;
  width: 100%;
  z-index: 2;
  background-color: #fff;
    border-top: 1px solid #f5f4f9;
}
.moneyCss{
  color: #f16161;
}
.noHuanHang{
  white-space:nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.reMenTag{
  border: 1px solid #53cdf5;
  color: #53cdf5;
  background-color: rgb(255,255,255,0);
  font-size: 6px;
  border-radius: 3px;
  padding: 1px;
}
.imgCol{
    display:flex;
    align-items:center;
    justify-content:center
}
.el-main {
    padding: 0px ;
}
.el-header{
  padding:0px;
}
.el-footer {
    padding:0px;
}
.words{
    color:#707070;
}
.littleWords{
  margin-top:5px;
    font-size: 13px;
}

.mainIconSize{
    height:23px;
}
.van-swipe__indicator--active {
    background-color: #fff;
}
.isFixed{
  position: fixed;
  top: 0;

  width: 100%;
  /* bottom: 0; */
 
}
</style>
